#include "process.h"

const char *str = "|/-\\";
// 版本1
void process1() {
    int i = 0;
    char bar[MAX_SIZE + 1] = { 0  };
    int len = strlen(str);
    while (i <= 100) {
        printf("[%-100s][%-2d%%][%c]\r", bar, i, str[i % len]);
        // 刷新缓冲区
        fflush(stdout);
        usleep(PUA);
        bar[i] = CH;
        i++;
    }
    printf("\n");
}
// 版本2
void process2(int rate) {
     static char bar[MAX_SIZE + 1] = { 0  };
    int len = strlen(str);
    if (rate <= 100 && rate >= 0) {
        printf("[%-100s][%-2d%%][%c]\r", bar, rate, str[rate % len]);
        // 刷新缓冲区
        fflush(stdout);
        usleep(PUA);
        bar[rate] = CH;
    }
    if (rate == MAX_SIZE) {
        memset(bar, '\0', sizeof(bar));
    }
}
// 版本3
void process3(int rate) {
    static char bar[MAX_SIZE + 1] = { 0  };
    int len = strlen(str);
    static int cnt = 0;
    if (rate <= 100 && rate >= 0) {
        cnt++;
        printf("[%-100s][%-2d%%][%c]\r", bar, rate, str[cnt % len]);
        // 刷新缓冲区
        fflush(stdout);
        usleep(PUA);
        bar[rate] = CH;
    }
    if (rate == MAX_SIZE) {
        memset(bar, '\0', sizeof(bar));
    }
}
